package com.foreknow.homework1;

import java.util.Scanner;

public class Game {
    Scanner input = new Scanner(System.in);
    private Person person;
    private Computer computer;
    private int count;
    public Game(){
        person = new Person();
        computer = new Computer();
    }
    public void init(){
        System.out.println("---------------欢迎来到游戏世界---------------");
        System.out.println("         **************************          ");
        System.out.println("         *********猜拳 开始*********          ");
        System.out.println("         **************************          ");
        System.out.println("出拳规则：1.剪刀 2.石头 3.布");
        System.out.println("请选择对方角色（1.刘备 2.孙权 3.曹操）");
        int a = input.nextInt();
        switch (a){
            case 1:
                computer.setName("刘备");
                break;
            case 2:
                computer.setName("孙权");
                break;
            case 3:
                computer.setName("曹操");
        }
        System.out.println("请输入你的姓名");
        person.setName(input.next());
        System.out.println(person.getName()+" vs  "+computer.getName()+"    对战");
    }
    public void star(){
        int comfenshu;
        int perfenshu;
        System.out.println("要开始吗(y/n)");
        String s = input.next();
        while (s.equals("y")){
            String shuying = "";
            System.out.println("请出拳：1.剪刀 2.石头 3.布（输入相应数字）");
            person.Showfirst();
            computer.chuquan();
            System.out.println("你出拳："+person.getJieguo());
            System.out.println(computer.getName()+"出拳："+computer.getJieguo());
            if (computer.getChuquan() == 1 && person.getChuquan() == 1 ||
                    computer.getChuquan() == 2 && person.getChuquan() == 2 ||
                    computer.getChuquan() == 3 && person.getChuquan() == 3){
                shuying = "平局";
            } else if (computer.getChuquan() == 1 && person.getChuquan() == 3 ||
                    computer.getChuquan() == 2 && person.getChuquan() == 1 ||
                    computer.getChuquan() == 3 && person.getChuquan() == 2){
                shuying = "你输了";
                comfenshu = computer.getScore();
                comfenshu++;
                computer.setScore(comfenshu);
            } else{
                shuying = "你赢了";
                perfenshu = person.getScore();
                perfenshu++;
                person.setScore(perfenshu);

            }count++;
            System.out.println("结果：" +" "+shuying);
            System.out.println("  ");
            System.out.println("是否开启下一轮(y/n)");
            s = input.next();
        }
    }
    public void showResult(){
        String bisaijieguo = "";
        System.out.println(person.getName()+" vs  "+computer.getName());
        System.out.println("对战次数："+ count);
        System.out.println(" ");
        System.out.println("姓名"+"  "+"得分");
        System.out.println(person.getName()+"  "+person.getScore());
        System.out.println(computer.getName()+"  "+computer.getScore());
        if (person.getScore() > computer.getScore()){
            bisaijieguo = "恭喜你赢了";
        }else if(person.getScore() == computer.getScore()){
            bisaijieguo = "平局";
        } else {
            bisaijieguo = "可惜你输了";
        }
    }
}
